/**
 * 作业下发详情
 */
import {
  Table,
  Radio,
  Space,
  Input,
  DatePicker,
  Select,
  Divider,
  Descriptions,
  Upload,
  message,
  Button,
  Checkbox,
  Form,
  Row,
  Col,
} from 'antd';
import request from '@/http';
import * as React from 'react';
import { Link } from 'react-router-dom';
const Option = Select;
import style from './details.less';
import { UploadOutlined } from '@ant-design/icons';

function onChange(checkedValues) {
  console.log('checked = ', checkedValues);
}

const props = {
  name: 'file',
  action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
  headers: {
    authorization: 'authorization-text',
  },
  onChange(info) {
    if (info.file.status !== 'uploading') {
      console.log(info.file, info.fileList);
    }
    if (info.file.status === 'done') {
      message.success(`${info.file.name} file uploaded successfully`);
    } else if (info.file.status === 'error') {
      message.error(`${info.file.name} file upload failed.`);
    }
  },
};

const details = (prop: any) => {
  /**
   * 上传文件，得到文件
  //  */
  // const test = () => {
  var [fileList, setFileList] = React.useState([]);
  const [formObject] = Form.useForm();
  const test = async (e) => {
    // console.log(e.target.files)
    let formdata = new FormData();
    formdata.append('file', e.target.files[0]);
    // request.post('/homeWork_manager_module/fileUpload', formdata).then(res => {
    //   setFileList(res)
    //   console.log(filename);
    // })
    const result: any = await request.post('/common/a_t_s/upload', formdata);
    setFileList(result.data);
    console.log(result.data);
  };
  // 得到上个页面传参
  let workId;
  if (prop.location && prop.location.state) {
    workId = prop.location.state.workId;
  }
  //查询作业信息
  const [data1, setData] = React.useState({
    courseName: '',
    studentName: '',
    teamName: '',
    workPlanTime: '',
    workTitle: '',
    workType: '',
  });
  const loadData = async () => {
    const result: any = await request.post(
      '/homeWork_manager_module/teacher/queryDistributionHomeWork',
      {
        workId: workId,
      },
    );
    if (result.success) {
      setData(result.data);
    }
  };
  // 页面预加载
  React.useEffect(() => {
    loadData();
  }, []);
  return (
    <div>
      <Descriptions title="作业详情">
        <Descriptions.Item label={'作业主题'}>
          {data1.courseName}
        </Descriptions.Item>
        <Descriptions.Item label={'计划完成时间'}>
          {data1.workPlanTime}
        </Descriptions.Item>
        <Descriptions.Item label={'课程名字'}>
          {data1.courseName}
        </Descriptions.Item>
        <Descriptions.Item label={'作业类型'}>
          {data1.workType}
        </Descriptions.Item>
        <Descriptions.Item label={'小组名字'}>
          {data1.teamName}
        </Descriptions.Item>
      </Descriptions>
      <Space style={{ marginBottom: '2rem' }}>
        <div
          className="site-input-group-wrapper"
          style={{ marginTop: 30, marginLeft: 20 }}
        >
          <span style={{ marginTop: '2rem', marginBottom: '1rem' }}>
            上传相关附件
          </span>
          <br></br>
          <input type="file" onChange={test} />
          <div style={{ marginTop: '2rem', marginBottom: '1rem' }}>
            <Link to="/Teacher/Assignment/Issue/index">
              <Button>返回</Button>
            </Link>
          </div>
        </div>
      </Space>
    </div>
  );
};
export default details;
